package com.example.love_margin.Controller;


import com.example.love_margin.Entity.Science;
import com.example.love_margin.Service.ScienceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Api(value = "科普",tags = "管理科普")
@RestController
@RequestMapping(value = "/Science" ,name = "科普信息")
public class ScienceController {

    @Autowired
    ScienceService scienceService;

    @ApiOperation(value = "发布科普信息",notes = "需要：science_title，science_picture，science_type")
    @PostMapping(value = "/addScience")
    public Object addScience(@RequestBody Science science){
        return scienceService.addScience(science);
    }

    @ApiOperation(value = "删除单个科普", notes = "删除单个科普")
    @PostMapping(value = "/deleteScience")
    public Object deleteScience(@RequestParam int science_id) {
//        System.out.println(Arrays.toString(science_id));
        return scienceService.deleteScience(science_id);
    }

    /*
批量删除
*/
    @ApiOperation(value = "删除多个科普", notes = "删除多个科普")
    @PostMapping(value = "/deleteScienceMany")
    public Object deleteScienceMany(@RequestBody Integer[] science_ids) {
        System.out.println(Arrays.toString(science_ids));
        return scienceService.delScienceMany(science_ids);
    }




    @ApiOperation(value = "修改单个科普", notes = "修改单个科普")
    @PostMapping(value = "/updateScience")
    public Object updateScience(@RequestBody Science science) {
        return scienceService.updateScience(science);
    }





    @ApiOperation(value = "查询单个科普", notes = "查询单个科普")
    @GetMapping(value = "/selectScienceOne")
    public Object selectScienceOne(@RequestParam int science_id) {
//        System.out.println(Arrays.toString(science_id));
        return scienceService.selectScienceOne(science_id);
    }


    @ApiOperation(value = "查询三条科普", notes = "查询三条科普")
    @GetMapping(value = "/selectScienceM")
    public Object selectScienceM() {
//        System.out.println(Arrays.toString(science_id));
        return scienceService.selectScienceOne();
    }


    //分页查询多个科普
    @ApiOperation(value = "分页查询多个科普", notes = "某字段，页码，每页条数")
    @GetMapping(value = "/selectScienceMany")
    public Object selectScienceMany(@RequestParam(required = false) String science_id,
                                    @RequestParam(required = false) Integer pageNum,
                                    @RequestParam(required = false) Integer pageSize) {
        return scienceService.selectScienPage(science_id,pageNum,pageSize);
    }



}
